package org.nacos.consumer.controller;

import java.util.Map;

import org.nacos.consumer.config.ProducerConfig;
import org.nacos.consumer.service.IOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
public class ConsumerController {

	@Autowired
	@Qualifier("loadBalanced")
    private RestTemplate loadBalanced;

	@Autowired
    private IOrderService orderService;
	
	@Autowired
    private ProducerConfig productConfig;

    @RequestMapping(value = "/echo/{str}", method = RequestMethod.GET)
    public String echo(@PathVariable String str) {
        return loadBalanced.getForObject("http://service-provider/echo/" + str, String.class);
    }
    
    @RequestMapping(value = "/test/route")
    public String route() {
        return "test route!";
    }
    
	@RequestMapping(value = "/service/{type}", method = RequestMethod.GET)
    public Map<String, Object> getService(@PathVariable Integer type) {
    	Map<String, Object> map = orderService.getService(type);
    	return map;
    }
	
	@RequestMapping(value = "/rocket/send")
    public String send(String message) {
        productConfig.sendMessage(message);
        return "send success !";
    }

}
